home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / indx18eu.zip / IREAD.PAS < prev    next >
Pascal/Delphi Source File  |  1991-03-20  |  4KB  |  182 lines

  1. PROGRAM TestIndexes ;
  2.  
  3. USES
  4.        DOS ,
  5.        CRT ,
  6.        IndexedFiles ;
  7.  
  8. CONST
  9.        IndexedFileName                             = 'INDEXED' ;
  10.  
  11.  
  12. TYPE
  13.  
  14.        MyRec                                     = RECORD
  15.  
  16.          index                                   : IndexStr ;
  17.          name                                    : STRING ;
  18.          age                                     : BYTE ;
  19.          salary                                  : REAL ;
  20.          occurance                               : INTEGER ;
  21.          phone                                   : STRING ;
  22.  
  23.        END ;  {  MyRec  }
  24.  
  25. VAR
  26.        f                                         : IFile ;
  27.        temp                                      : MyRec ;
  28.        i                                         : INTEGER ;
  29.        yourIndex                                 : LONGINT ;
  30.        ch                                        : CHAR ;
  31.  
  32.  
  33.  FUNCTION    Index_Convert (     s               : STRING )
  34.                                                  : STRING ;
  35.  
  36.    BEGIN  {  Index_Convert  }
  37.  
  38.      WHILE ( Length ( s ) < 10 )
  39.       DO
  40.        BEGIN
  41.  
  42.          s := '0' + s ;
  43.  
  44.        END ;  {  WHILE  }
  45.  
  46.      Index_Convert := s ;
  47.  
  48.    END ;  {  Index_Convert  }
  49.  
  50.  
  51.  FUNCTION StrNum (     n                         : LONGINT )
  52.                                                  : STRING ;
  53.  
  54.   VAR
  55.        s                                         : STRING ;
  56.  
  57.    BEGIN  {  StrNum  }
  58.  
  59.      Str ( n , s ) ;
  60.      StrNum := s ;
  61.  
  62.    END ;  {  StrNum  }
  63.  
  64.  
  65.  
  66.  
  67.  
  68. BEGIN
  69.  
  70.   ClrScr ;
  71.  
  72.   AssignIndexed ( f , IndexedFileName ) ;
  73.   ResetIndexed ( f ) ;
  74.  
  75.     WITH temp
  76.      DO
  77.       BEGIN
  78.  
  79.         FOR i := 0 TO 20
  80.          DO
  81.           BEGIN
  82.  
  83.             index := Index_Convert ( StrNum ( i ) ) ;
  84.  
  85.             ReadIndexed ( f , temp , SizeOf ( MyRec ) ) ;
  86.  
  87.             IF ( fileError = 0 )
  88.              THEN
  89.               BEGIN
  90.  
  91.                 WriteLn ;
  92.                 WriteLn ( 'INDEX :  [' , index , ']' ) ;
  93.                 WriteLn ( '    NAME             : ' , name ) ;
  94.                 WriteLn ( '    AGE :  ' , age:3 , '     SALARY: ' , salary:7:2 ) ;
  95.                 WriteLn ( '    PHONE            : ' , phone ) ;
  96.                 WriteLn ( 'This is occurance # ' , occurance ) ;
  97.  
  98.                 ch := ReadKey ;
  99.  
  100.               END    {  IF  }
  101.  
  102.              ELSE
  103.               BEGIN
  104.  
  105.                 WriteLn ;
  106.                 WriteLn ( ' Error with index [' , index:10 , ']!' ) ;
  107.                 WriteLn ( 'This means :  ' , IndexedError ( fileError ) ) ;
  108.  
  109.                 fileError := 0 ;    {  Not needed, but ...  }
  110.  
  111.               END ;  {  ELSE  }
  112.  
  113.           END ;  {  FOR i  }
  114.  
  115.         WriteLn ;
  116.         WriteLn ( 'Press any key to continue. ' ) ;
  117.         ch := ReadKey ;
  118.         ClrScr ;
  119.  
  120.         Write ( 'Change or add index :  ' ) ;
  121.         ReadLn ( yourIndex ) ;
  122.  
  123.         index := Index_Convert ( StrNum ( yourIndex ) ) ;
  124.  
  125.         Write ( 'NAME             : ' ) ;
  126.         ReadLn ( name ) ;
  127.  
  128.         Write ( 'AGE              :  ' ) ;
  129.         ReadLn ( age ) ;
  130.  
  131.         Write ( 'SALARY          : ' ) ;
  132.         ReadLn ( salary ) ;
  133.  
  134.         Write ( 'PHONE           : ' ) ;
  135.         ReadLn ( phone ) ;
  136.  
  137.         ClrScr ;
  138.  
  139.         occurance := IndexFileSize ( f.indexFile ) ;
  140.  
  141.         WriteIndexed ( f , temp , SizeOf ( MyRec ) ) ;
  142.  
  143.         FOR i := 0 TO ( yourIndex + 10 )
  144.          DO
  145.           BEGIN
  146.  
  147.             index := Index_Convert ( StrNum ( i ) ) ;
  148.  
  149.             ReadIndexed ( f , temp , SizeOf ( MyRec ) ) ;
  150.  
  151.             IF ( fileError = 0 )
  152.              THEN
  153.               BEGIN
  154.  
  155.                 WriteLn ;
  156.                 WriteLn ( 'INDEX    :  [' , index ,  ']' ) ;
  157.                 WriteLn ( '   NAME             : ' , name ) ;
  158.                 WriteLn ( '   AGE :  ' , age:3 , '     SALARY: ' , salary:7:2 ) ;
  159.                 WriteLn ( '   PHONE            : ' , phone ) ;
  160.                 WriteLn ( 'This is occurance # ' , occurance ) ;
  161.  
  162.                 ch := ReadKey ;
  163.  
  164.               END    {  IF  }
  165.  
  166.              ELSE
  167.               BEGIN
  168.  
  169.                 WriteLn ;
  170.                 WriteLn ( 'File Error! ' , IndexedError ( fileError ) ) ;
  171.  
  172.                 fileError := 0 ;
  173.  
  174.               END ;  {  ELSE  }
  175.  
  176.           END ;  {  FOR i  }
  177.  
  178.       END ;  {  WITH temp  }
  179.  
  180.     CloseIndexed ( f ) ;
  181.  
  182. END.